package net.aiion.weave.reader;

import java.util.LinkedList;

public class Context
{
    private LinkedList<Sink> sinks;

    private int s;
    private Event e;

    public Context() {
        sinks = new LinkedList<>();
    }

    public void addSink(Sink sink) {
        sinks.add(sink);
    }

    public Event getEvent() {
        return e;
    }

    public void forwardEvent(Event e) {
        if (s < sinks.size()) {
            Sink o = sinks.get(s++);
            Event oe = this.e;
            this.e = e;
            o.handleEvent(this);
            this.e = oe;
            s--;
        }
    }
}
